﻿using System.Web;
using System.Web.Mvc;
using Illinois.Core.Models;

namespace Illinois.UI.Controllers
{
  public abstract class BaseController : Controller
  {
    protected const string UserSessionName = "_USER_";

    private User _currentUser;
    protected User CurrentUser
    {
      get
      {
        if (_currentUser == null && HttpContext.Session != null)
        {
          _currentUser = (User)HttpContext.Session[UserSessionName];
        }
        return _currentUser;
      }
    }

    protected override void OnActionExecuting(ActionExecutingContext filterContext)
    {
      if (CurrentUser == null && filterContext.Controller.GetType() != typeof(LogInController))
      {
        filterContext.Result = new RedirectResult(Url.Action("Index", "LogIn"));
      }
    }
  }
}
